<template>
	<view class="select-picker">
		<view class="header">
			<view class="line"></view>
		</view>
		<view class="content">
			<view class="title" v-if="title.length">
				<view class="title-item" v-for="(item, index) in title" :key="index">
					{{ item }}
					<text>{{ list[index][value[index]] }}</text>
				</view>
			</view>
			<picker-view style="width: 100%; height: 300rpx;" :value="value" @change="bindChange">
				<picker-view-column v-for="(item, i) in list" :key="i">
					<view :class="['select_item']" v-for="(item, index) in list[i]" :key="index">
						{{ type===1?item.brandName:item }}</view>
				</picker-view-column>
			</picker-view>
		</view>
		<view class="select-picker-bottom">
			<view class="select-picker-save" @click="handleSave">确定</view>
		</view>
	</view>
</template>

<script>
export default {
	props: {
		// 传入数组
		list: {
			type: Array
		},
		type: {
			type: Number,
			default: 1
		},
		title: {
			type: Array,
			default: ()=>[]
		},
		active: {
			type: Array
		}
	},
	data() {
		return {
			value: this.active
		};
	},
	watch: {
		active(newValue) {
			this.value = newValue;
		}
	},
	computed: {},
	created() {
		// console.log(this.list, 1125255211);
	},
	methods: {
		bindChange(e) { 
			// 如果数组只有一项
			this.value = e.detail.value;
			this.$emit('bindChange',e.detail.value);
		},
		handleSave() {
			console.log('点击了保存');
			setTimeout(() => {
				const a = this.value[0];
				if (this.list.length === 1) {
					this.$emit('close', {
						index: this.value[0],
						type: 1
					});
				} else { 
					this.$emit('close', this.value);
				}
			}, 1000);
		}
	}
};
</script>
<style>
	/* .active{
		color:#0091ff;
		width: 100%;
		height: 96rpx;
	} */
</style>
<style lang="scss" scoped>
	.select_item {
		display: flex;
		justify-content: center;
		align-items: center;
		// color: #0091ff;
		// padding-bottom: 30rpx;
	}

	.select-picker {
		background: #ffffff;
		border-radius: 8rpx 8rpx 0rpx 0rpx;
		box-shadow: 0rpx -4rpx 12rpx 0rpx rgba(0, 0, 0, 0.12);
		position: relative;
		z-index: 30;

		.header {
			height: 67rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			border-top: 2rpx solid #eeeeee;
			border-bottom: 2rpx solid #eeeeee;

			.line {
				width: 64rpx;
				height: 10rpx;
				opacity: 1;
				background: #d8d8d8;
				border-radius: 6rpx;
			}
		}

		.content {
			.title {
				display: flex;
				// flex: 1;
				width: 100%;

				.title-item {
					font-size: 32rpx;
					display: flex;
					flex: 1;
					justify-content: center;
					padding: 36rpx 0 30rpx 0;
					color: #333333;
					font-weight: 500;

					text {
						margin-left: 24rpx;
					}
				}
			}
		}

		.select-picker-bottom {
			padding: 30rpx 40rpx;

			.select-picker-save {
				display: flex;
				color: #fff;
				font-weight: 500;
				height: 70rpx;
				background: #0091ff;
				border-radius: 8rpx;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>
